﻿using GamFi.Admin.API.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace GamFi.Admin.API.Persistence.Configurations;

public class UserConfiguration: IEntityTypeConfiguration<User>
{
    /// <inheritdoc />
    public void Configure(EntityTypeBuilder<User> builder)
    {
        builder.HasKey(x => x.Id);

        builder.Property(p => p.WalletId);
            
        builder.HasOne(x => x.UserInfo)
            .WithOne(y => y.User)
            .HasForeignKey<User>(x => x.Id)
            .OnDelete(DeleteBehavior.Cascade);

        builder.HasOne(x => x.Wallet)
            .WithOne(y => y.User)
            .HasForeignKey<User>(x => x.WalletId)
            .OnDelete(DeleteBehavior.Cascade);
    }
}